<%@ page language="java" import="com.ruohi.manage.*,java.util.*,java.sql.*,com.ruohi.util.dbutil.*,com.ruohi.util.common.*" pageEncoding="UTF-8"%><%
	Connection connection = null;
	Map adminInfo = (Map)session.getAttribute("adminInfo");
	DBHelper dbHelper = DBHelper.getInstance();
	Map model = new HashMap();
	String tableName = "service_work";
	try{
		connection = PoolManager.getConnection(DBType.getDBTypeByEnum("106010"));
		String id = CommonString.getFormatPara(request.getParameter("id"));
		String channelUUID = CommonString.getFormatPara(request.getParameter("channel_uuid"));
		if(null!=id&&!"".equals(id)){
			model = dbHelper.getMap(" select * from "+tableName+" where uuid = ? ",new Object [] {id} , connection);
		}
		if("".equals(channelUUID)&&null!=model){
			channelUUID = (String)model.get("channel_uuid");
		}
		List<Map> categoryList = dbHelper.getMapList(" select uuid,name from service_work_category where user_uuid = ? ",new Object [] {adminInfo.get("uuid")},connection);
		Map categoryMap = CommonCollection.listToMap(categoryList,"uuid","name");
		LinkedHashMap linkTypeMap = (LinkedHashMap)CommonApplication.getEnumChildren("109",application);
		String sql = "";
		if(adminInfo.get("usern").toString().equals("admin")){
			sql = " select uuid,parent_uuid,name,action_link from "+"service_common_channel "; 
		}else if(adminInfo.get("role_uuid").toString().equals("4CCDF227-7F10-4E09-A47C-085CCB4A45FF")){//如果角色为空的话
			sql = " select pcc.uuid,pcc.parent_uuid,pcc.name,pcc.action_link  ";
			sql += " from "+"service_common_channel pcc , "+"service_common_role_resource pcrr ";
			sql += " where pcc.uuid = pcrr.resource_uuid and pcrr.usern = '"+adminInfo.get("usern")+"' ";
		}else{
			sql = " select pcc.uuid,pcc.parent_uuid,pcc.name,pcc.action_link  ";
			sql += " from "+"service_common_channel pcc , "+"service_common_role_resource pcrr ";
			sql += " where pcc.uuid = pcrr.resource_uuid and pcrr.role_uuid = '"+adminInfo.get("role_uuid")+"' ";
		}
		sql += " order by order_no asc ";
		List<Map> channels = dbHelper.getMapList(sql,connection);
		StringBuffer tree = new StringBuffer();
		String parentUUID = "";
		String UUID = "";
		String actionLink = "";
		String name = "";
		for(Map m : channels){
			UUID = (String)m.get("uuid");
			parentUUID = m.get("parent_uuid")==null?"0":(String)m.get("parent_uuid");
			actionLink = (String)m.get("action_link");
			name = (String)m.get("name");
			tree.append("{ id:'"+UUID+"', pId:'"+parentUUID+"', name:'"+name+"'");
			tree.append(",click:\"setPar('"+UUID+"','"+name+"','"+actionLink+"')\"");
			if(parentUUID.toString().equals("0")){
				tree.append(",open:true");
			}
			tree.append("},");
		}
		if(tree.length()>1&&tree.indexOf(",")!=-1){
			tree.setLength(tree.length()-1);
		}
%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title><%=Env.getInstance().getProperty("project_name") %></title>
    <link rel="stylesheet" type="text/css" href="/plugin/tree/ztree/zTreeStyle/zTreeStyle.css" />
	<link href="/plugin/ui/ligerUI/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
	<link href="/plugin/ui/ligerUI/ligerUI/skins/Gray/css/all.css" rel="stylesheet" type="text/css" />
	<link href="/plugin/ui/ligerUI/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
	<link href="/backend/style/style.css" rel="stylesheet" type="text/css" />
	<script src="/plugin/jquery/jquery.min.js" type="text/javascript"></script>
  </head>
  
  <body style="margin: 0;padding: 0; overflow: hidden; ">
	<form name="theform" id="theform" action="/backend/action/crud.jsp?enumNo=106010">
		<div class="formDiv">
				<div class="formLeft">类<span class="span2"></span>别</div>
				<div class="formRight" style="width: 300px;">
					<input type="text" readonly="readonly" class="jr_text" id="zd_channel_name" name="zd_channel_name" value="<%=CommonString.getFormatPara(model.get("channel_name")) %>" />
					<input type="hidden" id="zd_channel_uuid" name="zd_channel_uuid" value="<%=CommonString.getFormatPara(model.get("channel_uuid")) %>" />
				</div>
				<div class="formRight" style="width: 130px;">
					（单击请选择类别）
				</div>
				<div style="clear:left;"></div>
				<div class="formLeft">类<span class="span2"></span>别</div>
				<div class="formRight">
					<%
						String category_uuid = CommonString.getFormatPara(model.get("category_uuid"));
						if("".equals(category_uuid)){
							String _category_uuid = CommonString.getFormatPara(request.getParameter("category_uuid"));
							category_uuid = _category_uuid;
						}
					%>
					<select dataType='Require' msg='请选择类别！' class="jr_select" name="zd_category_uuid" id="zd_category_uuid">
						<option value="">--请选择类别-</option>
						<%=CommonForm.createSelect(categoryMap,category_uuid) %>
					</select>
				</div>
				<div style="clear:left;"></div>
				<div class="formLeft">名<span class="span2"></span>称</div>
				<div class="formRight">
					<input type="text" dataType='Require' msg='请输入名称！' class="jr_text" name="zd_name" id="zd_name" value="<%=CommonString.getFormatPara(model.get("name")) %>" />
				</div>
				<div style="clear:left;"></div>
				<div class="formLeft">链接方式</div>
				<div class="formRight">
					<%
						String link_target = CommonString.getFormatPara(model.get("link_target"));
						if("".equals(link_target)){
							link_target = "109002";	
						}
					%>
					<select class="jr_select" name="zd_link_target" id="zd_link_target">
						<%=CommonForm.createSelect(linkTypeMap,link_target) %>
					</select>
				</div>
				<div style="clear:left;"></div>
				<div class="formLeft">链<span class="span2"></span>接</div>
				<div class="formRight">
					<input type="text" dataType='Require' msg='请输入链接！' class="jr_text" name="zd_link" id="zd_link" value="<%=CommonString.getFormatPara(model.get("link")) %>" />
				</div>
				<div style="clear:left;"></div>
		</div>
		<div style="clear: left;"></div>
		<input type="hidden" name="tableName" id="tableName" value="<%=tableName %>" />
		<input type="hidden" name="zd_id" id="zd_id" value="<%=CommonString.getFormatPara(model.get("id")) %>" />
	</form>
  </body>
</html>
<script type="text/javascript" src="/plugin/jquery/jquery.form.js"></script>
<script src="/plugin/ui/ligerUI/ligerUI/js/ligerui.min.js" type="text/javascript"></script>
<script src="/plugin/date/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
<script src="/plugin/tree/ztree/jquery.ztree.all-3.1.js" type="text/javascript"></script>
<script src="/backend/scripts/common.js" type="text/javascript"></script>
<script src="/plugin/validator/wofoshan/validator.min.js" type="text/javascript"></script>
<script type="text/javascript">
	function doSub(){
		var rs = Validator.Validate(document.getElementById("theform"),1);
		if(rs){
			jQuery("#theform").ajaxSubmit({
				type : "POST",
				async : false ,
				success : function(data) {
					var rs = parseInt(jQuery.trim(data), 10);
					if (rs > 0 ) {
						jrSuccess("保存成功！");
						parent.document.getElementById("home").contentWindow.getMyCategory();
						<%
						if("".equals(id)){
							%>
						window.location.reload();
							<%
						}
						%>
					} 
				}
			});
		}
	}
	var channelNodes = [
		<%=tree.toString() %>
	];
	//下拉框的树形结构
	checkBoxTree({
		id : "zd_channel_name",
		zTreeNodes : channelNodes,
		top : -24 ,
		left : -1,
		width : 200,
		height : 150
	});
	function setPar(id,name,actionLink){
		jQuery("#zd_name").val(name);
		jQuery("#zd_link").val(actionLink+"?channel_uuid="+id);
		jQuery("#zd_channel_name").val(name);
		jQuery("#zd_channel_uuid").val(id);
		jQuery("#template_channel_zd_channel_name").hide();
	}
</script><%
	}catch(Exception e){
		e.printStackTrace();
	}finally{
		DBHelper.freeConnection(connection);
	}
%>